<template>
	<view>
		<back :showBackText="false" customClass="bg-gradual-blue text-white" title="题目反馈"></back>
		<view>
			<text class="text-label">请选择在做题过程中遇到的问题</text>
			<view class="feedback-layout">
				<view @tap="feedbackTypeTap" class="layout-item" :data-feedbacktype="item"
					:style="'background: ' + (item == feedbackType ? '#6097FE' : '#F5F5F5') + ';'"
					v-for="(item, index) in feedbackTypes" :key="index">
					<text class="text-item"
						:style="'color: ' + (item == feedbackType ? 'white' : '#333')">{{ item }}</text>
				</view>
			</view>
			<text class="text-label">具体描述</text>
			<view class="layout-content">
				<textarea @input="bindContentInput" class="input-content" placeholder="选填，描述详细情况"></textarea>
			</view>
			<view @tap="commitTap" class="btn-submit">提交</view>
		</view>
	</view>
</template>

<script>
	let app = getApp();
	let that = null;
	export default {
		data() {
			return {
				id: 0,
				feedbackContent: '',
				feedbackType: '',
				feedbackTypes: ['题目有错别字', '选项不合理', '答案解析不清晰或不合理', '题目分类不正确', '其他']
			};
		},
		onLoad(options) {
			(that = this).setData({
				id: options.id
			});
		},
		methods: {
			bindContentInput(e) {
				this.setData({
					feedbackContent: e.detail.value
				});
			},

			feedbackTypeTap(e) {
				let t = e.currentTarget.dataset.feedbacktype;
				this.setData({
					feedbackType: t
				});
			},

			commitTap() {
				if ('' != this.feedbackType) {
					app.globalData.server
						.postRequest('question/feedback', {
							question_id: that.id,
							content: that.feedbackType + '->' + that.feedbackContent
						})
						.then(function(e) {
							uni.showToast({
								title: '反馈成功!',
								mask: true,
								complete: function() {
									setTimeout(function() {
										uni.navigateBack();
									}, 1500);
								}
							});
						})
						.catch(function(t) {
							app.showToast('反馈失败');
							console.log(t);
						});
				} else {
					uni.showToast({
						icon: 'none',
						title: '请选择反馈类型'
					});
				}
			}
		}
	};
</script>
<style>
	@import './feedback.css';
</style>